package org.eyeTopLight.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

@Configuration
public class TokenConfig {

    /**
     * 对称加密密钥
     */
    private String SIGNING_KEY = "etl";
    /**
     * 将token信息存储在内存中，后续可以改成redis
     * @return
     */
    @Bean
    public TokenStore tokenStore() {
        return new JwtTokenStore(accessTokenConverter());
    }

    @Bean
    public JwtAccessTokenConverter accessTokenConverter() {
        JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
        converter.setSigningKey(SIGNING_KEY); //对称秘钥，资源服务器使用该秘钥来验证
        return converter;
    }

    /**
     *
     */
    //JWT添加自定义数据
    @Bean
    @ConditionalOnMissingBean(name="jwtTokenEnhancer")//这里中的是为了让我们自己的业务系统也可以提供自己的自定义数据模板
    public TokenEnhancer jwtTokenEnhancer(){
        return new TokenJwtEnhancer();
    }
}